package com.jchao.process.service.impl;


import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.jchao.model.process.ProcessTemplate;
import com.jchao.model.process.ProcessType;
import com.jchao.process.mapper.ProcessTypeMapper;
import com.jchao.process.service.ProcessTemplateService;
import com.jchao.process.service.ProcessTypeService;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;
import java.util.Map;
import java.util.stream.Collectors;

/**
 * <p>
 * 审批类型 服务实现类
 * </p>
 *
 * @author jchao
 * @since 2023-11-17
 */
@Service
public class ProcessTypeServiceImpl extends ServiceImpl<ProcessTypeMapper, ProcessType> implements ProcessTypeService {


    @Autowired
    private ProcessTemplateService processTemplateService;

    @Override
    public List<ProcessType> findProcessType() {
        List<ProcessType> processTypeList = baseMapper.selectList(null);
        Map<Long, List<ProcessTemplate>> templateMap = processTemplateService.list()
                .stream().collect(Collectors.groupingBy(ProcessTemplate::getProcessTypeId));
        for (ProcessType processType : processTypeList) {
            processType.setProcessTemplateList(templateMap.get(processType.getId()));
        }
        return processTypeList;
    }
}
